<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3班抽奖</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    h2 {
      text-align: center;
    }

    .box {
      width: 600px;
      margin: 50px auto;
      display: flex;
      font-size: 25px;
      line-height: 40px;
    }

    .qs {

      width: 450px;
      height: 40px;
      color: red;

    }

    .btns {
      text-align: center;
    }

    .btns button {
      width: 120px;
      height: 35px;
      margin: 0 50px;
    }
  </style>
</head>

<body>
  <h2>随机点名</h2>
  <div class="box">
    <span>大冤种：</span>
    <div class="qs">请点击开始进行抽奖</div>
  </div>
  <div class="btns">
    <button class="start">开始</button>
    <button class="end">结束</button>
  </div>

  <script>
    // 数据数组
    const arr = ["陈政睿", "钟芳艳", "艾轶群", "周胜", "段晓倩", "李文杰", "胡玥", "舒伟俊", "晏雄伟", "陈旺鸿", "谢佳欣", "曾苏", "刘俊良", "叶可轩", "朱思羽", "徐能勇", "林佩斯", "黄清林", "程伟华", "钟晓东", "谭睿", "于勇乐", "凌鹏", "熊梦扬", "肖孝洋", "张坚", "欧阳浩杰", "邱欣林", "张伟安", "胡伟斌", "黄惠文", "万里鹏", "崔美琪", "黄思兴", "余笑慧", "梁鑫", "范宇杭", "曾煌煌", "周瑜欣", "李伊婷", "龚栎灵", "彭志轩", "黄中旺", "彭家洋", "曾锦斌", "吴祥锦", "周澎", "聂梓浩", "肖意", "杜明鹏", "刘科", "简荣辉", "曾庆民", "崔子豪", "邓宇奇", "阙学烨"]
    // 定时器的全局变量
    let timerId = 0
    // 随机号要全局变量
    let random = 0
    // 业务1.开始按钮模块
    const qs = document.querySelector('.qs')
    // 1.1 获取开始按钮对象
    const start = document.querySelector('.start')
    // 1.2 添加点击事件
    start.addEventListener('click', function () {
      timerId = setInterval(function () {
        // 随机数
        random = parseInt(Math.random() * arr.length)
        // console.log(arr[random])
        qs.innerHTML = arr[random]
      }, 1)
    })

    // 2. 关闭按钮模块
    const end = document.querySelector('.end')
    end.addEventListener('click', function () {
      clearInterval(timerId)
    })
  </script>
</body>

</html>